//
//  ZQJMessageFrame.m
//  QQ聊天界面
//
//  Created by 3tee on 2021/6/7.
//  Copyright © 2021年 3tee. All rights reserved.
//

#import "ZQJMessageFrame.h"
#import <UIKit/UIKit.h>
#import "ZQJMessage.h"

@implementation ZQJMessageFrame

- (void)setMessage:(ZQJMessage *)message{
    _message = message;
    CGFloat padding = 8;
    //计算时间frame
    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
    if (!message.isHidenTime) {
        _timeFrame = CGRectMake(0, 0, screenW, 20);
    }
    //计算头像frame
    CGFloat iconW = 48;
    CGFloat iconX = message.type == ZQJMessageMe ? screenW - padding - iconW : padding;
    _iconFrame = CGRectMake(iconX, CGRectGetMaxY(_timeFrame), iconW, iconW);
    
    //计算用户名frmae
    CGFloat nameX = message.type == ZQJMessageOther ? padding + _iconFrame.size.width  : screenW - padding - iconW  - 60;
    _nameFrame = CGRectMake(nameX,  CGRectGetMinY(_iconFrame), 60, 20);
    
    //计算内容frame
    //计算聊天内容的字体宽高
    CGRect contentSize = [message.msg boundingRectWithSize:CGSizeMake(250, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    //因为设置了内容的内边距上下15 左右20 所以把btn的宽高变大30 和40；
    contentSize.size.width += 40;
    contentSize.size.height += 30;
    CGFloat contentX = message.type == ZQJMessageOther ? padding + _iconFrame.size.width : screenW - padding - iconW -contentSize.size.width;
    
    
    
    NSLog(@"conentSize = %f",contentSize.size.height);
    _contentFrame = CGRectMake(contentX, CGRectGetMaxY(_nameFrame), contentSize.size.width, contentSize.size.height);
    _rowHeight = MAX(CGRectGetMaxY(_contentFrame),CGRectGetMaxY(_iconFrame)) +padding;
}

@end
